package cn.scu.ne04jdemo.controller;

import cn.scu.ne04jdemo.entitiy.ScheProdTaskInfoEntity;
import cn.scu.ne04jdemo.entitiy.ScheTaskDevInfoEntity;
import cn.scu.ne04jdemo.service.ScheTaskDevInfoService;
import cn.scu.ne04jdemo.vo.ScheTaskDevInfoVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sche/task/dev/info")
public class ScheTaskDevInfoController {

    @Autowired
    private ScheTaskDevInfoService scheTaskDevInfoService;
    @GetMapping("/findPage")
    public ResponseEntity<IPage> findPage(@RequestParam(required = false) String prodTypeId
            , @RequestParam(required = true) long pageNum, @RequestParam(required = true)  long pageSize){
//        QueryWrapper<ScheTaskDevInfoEntity> params = new QueryWrapper();
//        params.like(StringUtils.isNotBlank(prodTypeId), "prod_type_id", prodTypeId);
//        IPage<ScheTaskDevInfoEntity> page = new Page<ScheTaskDevInfoEntity>(current, size);
//        try {
//            page = scheTaskDevInfoService.page(page, params);
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//        return page;
        try {
            IPage<ScheTaskDevInfoVo> page = this.scheTaskDevInfoService.findPage(prodTypeId, pageNum, pageSize);
            return ResponseEntity.ok(page);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }


    @PostMapping("/update")
    @ResponseBody
    public Boolean update(@RequestBody ScheTaskDevInfoEntity scheTaskDevInfoEntity){
        try {
            scheTaskDevInfoService.updateById(scheTaskDevInfoEntity);
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
        return true;
    }

}
